/*
 * Copyright @ 2024 weili23
 * com.hmdp.interceptor 16:36
 * All right reserved.
 */

package com.hmdp.interceptor;

import cn.hutool.core.bean.BeanUtil;
import com.hmdp.entity.User;
import com.hmdp.utils.UserHolder;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import java.util.Map;
import java.util.concurrent.TimeUnit;

import static com.hmdp.utils.RedisConstants.LOGIN_USER_KEY;
import static com.hmdp.utils.RedisConstants.LOGIN_USER_TTL;

/**
 * @desc: 登录拦截器
 * @author: weili23
 * @createTime: 2024/3/14 16:36
 * @version: v1.0
 */

public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //1.判断是否需要拦截，依据threadLocal中是否有用户
        if(UserHolder.getUser() == null){
            //用户不存在需要拦截
            response.setStatus(401);
            return  false;
        }
        return true;

    }


}
